package com.mathassistant.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mathassistant.client.presenter.TopicEditPresenter.Display;

public class TopicEditView extends DialogBox implements Display{

	private Label nameTopicLabel;
	private TextBox nameTopicTextbox;
	private Button saveButton;
	private Button closeButton;
	
	public TopicEditView() {
		CreateUI();
		showDialog();
		
		nameTopicTextbox.setFocus(true);
	}
	
	public TopicEditView(String content) {
		// TODO Auto-generated constructor stub
		CreateUI();
		setContentAndShow(content);
		nameTopicTextbox.setFocus(true);
	}

	private void CreateUI(){
		this.setText("Thêm Chủ Đề");
		
		VerticalPanel verticalPanel = new VerticalPanel();
		verticalPanel.setStyleName("dlgLogin-horizontal");
		setWidget(verticalPanel);
		verticalPanel.setSize("400px", "100%");
		
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setStyleName("dlgLogin-horizontal");
		verticalPanel.add(horizontalPanel);
		horizontalPanel.setWidth("100%");
		
		nameTopicLabel = new Label("Tên chủ đề :");
		nameTopicLabel.setStyleName("dlgLogin-title");
		horizontalPanel.add(nameTopicLabel);
		
		HorizontalPanel horizontalPanel_1 = new HorizontalPanel();
		horizontalPanel_1.setStyleName("dlgLogin-horizontal");
		verticalPanel.add(horizontalPanel_1);
		horizontalPanel_1.setWidth("100%");
		
		nameTopicTextbox = new TextBox();
		horizontalPanel_1.add(nameTopicTextbox);
		nameTopicTextbox.setWidth("300px");
		nameTopicTextbox.addStyleName("dlgEditTopic-Textbox");
		
		HorizontalPanel horizontalPanel_2 = new HorizontalPanel();
		verticalPanel.add(horizontalPanel_2);
		horizontalPanel_2.setWidth("");
		
		saveButton = new Button("Lưu");
		horizontalPanel_2.add(saveButton);
		saveButton.setWidth("60px");
		saveButton.addStyleName("dlgLogin-button");
		
		Label lblAa = new Label("");
		lblAa.setStyleName("dlgLogin-Label");
		horizontalPanel_2.add(lblAa);
		
		closeButton = new Button("Thoat");
		closeButton.setText("Thoát");
		horizontalPanel_2.add(closeButton);
		closeButton.setWidth("60px");
		closeButton.addStyleName("dlgLogin-button");
	}

	@Override
	public HasClickHandlers getAddButton() {
		// TODO Auto-generated method stub
		return saveButton;
	}

	@Override
	public HasClickHandlers getCancelButton() {
		// TODO Auto-generated method stub
		return closeButton;
	}

	@Override
	public HasValue<String> getTopicContentTextBox() {
		// TODO Auto-generated method stub
		return nameTopicTextbox;
	}

	@Override
	public Widget asWidget() {
		// TODO Auto-generated method stub
		return this;
	}

	@Override
	public void hideDialog() {
		// TODO Auto-generated method stub
		this.hide(true);
	}

	@Override
	public void showDialog() {
		// TODO Auto-generated method stub
		setAnimationEnabled(true);
		setGlassEnabled(true);
		center();
		show();
	}

	@Override
	public void setContentAndShow(String content) {
		// TODO Auto-generated method stub
		this.nameTopicTextbox.setText(content);
		setAnimationEnabled(true);
		setGlassEnabled(true);
		center();
		show();
	}
}
